Component({
  data: {
    houseList: [],
    houseLayerVisible: false,
  },
  properties: {
    placeholder: { type: String, value: '请选择房屋' },
    houseId: { type: String },
    houseName: { type: String },
  },
  methods: {
    onSelectHouseLayer(e) {
      // 触发自定义事件：将选中的房屋对象，传出去，让使用该组件的人自己决定怎么使用房屋对象数据
      // <dgg-house-action-sheet-cell bind:selected="onSelectHouse" />
      this.triggerEvent('selected', e.detail)

      // 为了支持双向绑定
      // <dgg-house-action-sheet-cell model:house-id="{{ houseId }}" model:house-name="{{ houseName }}" />
      this.setData({
        houseId: e.detail.id,
        houseName: e.detail.name,
        houseLayerVisible: false, // 关闭action-sheet
      })
    },
    closeHouseLayer() {
      this.setData({ houseLayerVisible: false })
    },
    async openHouseLayer() {
      const res = await wx.http({
        url: '/house',
      })

      if (!res.data.length) {
        return wx.utils.toast('您暂无审核通过的房屋！')
      }

      this.setData({ houseList: res.data, houseLayerVisible: true })
    },
  },
})
